<div class='easyui-panel' noheader='true' style="padding:3px; overflow:hidden;" border='false' fit='true'><table id="user_qq_tt"></table></div>
<!-- Begin Add new user -->
<div id='user_qq_add_dd' class='easyui-dialog' title='添加新的QQ用户' style='width:300px;height:160px;padding:5px;' modal='true' closed='true'>
<div class="easyui-layout" fit='true' border='true'>
<div region='center' border='false'><form id='user_qq_add_ff' method="post">
用户昵称: <input type="input" name="name" class="easyui-validatebox" required="true" validType="length[4,64]" missingMessage="请输入用户昵称" invalidMessage="请输入0-64个字符" /><br />
&nbsp;&nbsp;QQ&nbsp;&nbsp;号:&nbsp;&nbsp; <input type="input" name="qq" class="easyui-validatebox" required="true" validType="qq" missingMessage="请输入用户QQ号" invalidMessage="请输入正确的QQ号" onchange="user_qq_add_ff.email.value=user_qq_add_ff.qq.value+'@qq.com';"/><br />
邮箱地址: <input type="input" name="email" class="easyui-validatebox" required="true" validType="email"  missingMessage="请输入邮箱地址" invalidMessage="请输入正确的邮箱格式" /><br />
</form>
</div>
<div region='south' style="height:30px; text-align:center; padding-top:5px;" border='false'><a href="javascript:void(0)" iconCls="icon-save" class="easyui-linkbutton" onclick="$('#user_qq_add_ff').submit()">添加</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" iconCls="icon-cancel" class="easyui-linkbutton" onclick="$('#user_qq_add_dd').dialog('close')">取消</a></div>
</div>
</div>
<!-- End Add new user -->
<!-- Begin Import data -->
<div id='user_qq_import_dd' class='easyui-dialog' title='导入新的防毒墙用户' style='width:380px;height:240px;padding:5px;' modal='true' closed='true'>
<div class="easyui-layout" fit='true' border='true'>
<div region='center' border='false'><form id='user_qq_import_ff' method="post" enctype="multipart/form-data">
<label>上传的文件格式如下:<br /><br />
[用户昵称],[QQ号],[用户邮箱]<br />
...<br /><br />
</label>
文件: <input type="file" name="file" style="width:300px;"/><br /><br />
</form>
<br /><div id="user_qq_import_p" class="easyui-progressbar" style="width:350px;"></div>
</div>
<div region='south' style="height:30px; text-align:center; padding-top:5px;" border='false'><a href="javascript:void(0)" iconCls="icon-save" class="easyui-linkbutton" onclick="$('#user_qq_import_ff').submit()">导入</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" iconCls="icon-cancel" class="easyui-linkbutton" onclick="$('#user_qq_import_dd').dialog('close')">取消</a></div>
</div>
</div>
<!-- Eng Inport data-->
<script language="javascript">
/*列表控件*/
$('#user_qq_tt').datagrid({
	title: 'QQ用户数据(上次更新时间)'
	, fit: true
	, url: 'test.json'
	, pagination: true /*底部分页栏*/
	, pageList: [100, 200, 500]
	, loadMsg: '正在加载数据，请稍等 ...'
	/*, queryParams: {onlydata:1}*/
	, frozenColumns:[[
	    	{field:'ck',checkbox:true}
		]]
	, columns:[[
			{field:'id', title:'ID序号', width:60}
			, {field:'qq', title:'QQ号', width:80}
			, {field:'name', title:'用户昵称', width:100}
			, {field:'email', title:'联系邮箱', width:200}
			, {field:'sem', title:'发送邮件(成功/失败)', width:120}
		]]  
	, toolbar:[{
			id:'user_qq_delete'
			, text: '删除选中'
			, iconCls: 'icon-remove'
			, handler: function(){
				/*删除选中用户*/
				var sels = $('#user_qq_tt').datagrid('getSelections');
				if(!sels.length){
					$.messager.alert('操作错误', '请先择要删除的项', 'error');
					return;
				}
				/*组合要删除的项*/
				var ids = ';';
				for(it in sels){
					ids += sels[it].id + ';';
				}
				/*发送删除的项*/
				$.ajax({type:'POST'
					, url:'test.action'
					, data:'type=delselect&ids=' + ids
					, dataType: 'json'
					, error: function(XMLHttpRequest, textStatus, errorThrown){
						$.messager.alert('错误', '请求失败:' + errorThrown, 'error');
					}
					, success:function(msg){
						if(msg.success){
							$.messager.alert('操作成功', '删除用户成功', 'info');
							$('#user_qq_tt').datagride('reload');
						} else {
							$.messager.alert('操作失败', '删除用户失败:'+msg.msg, 'error');
						}
					}
				});		
			}
		},{
			id:'user_qq_clear'
			, text: '清空数据'
			, iconCls: 'icon-remove'
			, handler: function(){
				/*清空所有用户*/
				$.messager.confirm('确认操作', '确实要删除所有的防毒墙用户信息吗?'
					, function(b){
						if(!b) return;
						$.ajax({type:'POST'
							, url: 'test.action'
							, data: 'type=delall'
							, dataType: 'json'
							, error: function(XMLHttpRequest, textStatus, errorThrown){
								$.messager.alert('错误', '请求失败:' + errorThrown, 'error');
							}
							,success: function(msg){
								if(msg.success){
									$.messager.alert('操作成功', '删除有用用户成功', 'info');
									$('#user_qq_tt').datagride('load');
								} else {
									$.messager.alert('操作失败', '删除所用有用户失败:'+msg.msg, 'error');
								}
							}
						});
					}
				);
			}
		},'-',{
			id: 'user_qq_add'
			, text: '添加新用户'
			, iconCls: 'icon-add'
			, handler:function(){
				$('#user_qq_add_ff').form('clear');
				$('#user_qq_add_dd').dialog('open');
			}
		},{
			id: 'user_qq_input'
			, text: '导入外部数据'
			, iconCls: 'icon-reload'
			, handler: function(){
				$('#user_qq_import_ff').form('clear');
				$('#user_qq_import_p').progressbar('setValue', '0');   
				$('#user_qq_import_dd').dialog('open');
			}
		}] 
});
/*Pagination 分页*/
$('#user_qq_tt').datagrid('getPager').pagination({
	displayMsg:'共有{total}条记录'
	, beforePageText: '当前显示第'
	, afterPageText: '页 共{pages}页'
});
/*添加操作*/
$('#user_qq_add_ff').form({
	url:''
	, dataType:'json'
	, onSubmit: function(){
		if( !$('#user_qq_add_ff').form('validate') ){
			$.messager.alert('错误', '请输入完整的信息', 'error');
			return false; // 验证不通过
		}
	}
	, error: function(XMLHttpRequest, textStatus, errorThrown){
		$.messager.alert('错误', '提交添加失败:' + errorThrown, 'error');
	}
	, success: function(msg){
		if(msg.success){
			$.messager.alert('操作成功', '添加新用户成功', 'info');
			$('#user_qq_add_dd').dialog('close');
			$('#user_qq_tt').datagride('load');
		} else {
			$.messager.alert('操作失败', '添加新用户失败:'+msg.msg, 'error');
		}
	}
});
/*导入防毒墙用户*/
$('#user_qq_import_ff').form({
	url:''
	, dataType:'json'
	, onSubmit: function(){
		if( 0 == user_qq_import_ff.file.value.length ){
			$.messager.alert('错误', '请选择要上传的文件', 'error');
			return false; // 验证不通过
		}
	}
	, error: function(XMLHttpRequest, textStatus, errorThrown){
		$.messager.alert('错误', '提交添加失败:' + errorThrown, 'error');
	}
	, success: function(msg){
		if(msg.success){
			$.messager.alert('操作成功', '添加新用户成功', 'info');
			$('#user_qq_add_dd').dialog('close');
			$('#user_qq_tt').datagride('load');
		} else {
			$.messager.alert('操作失败', '添加新用户失败:'+msg.msg, 'error');
		}
	}
});
</script>
